{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f99935cb-5201-45ec-953b-4bcdd86ca029",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Suite.SPADE: 0\n",
      "Suite.HEART: 1\n",
      "Suite.CLUB: 2\n",
      "Suite.DIAMOND: 3\n",
      "[♠Q, ♣4, ♠6, ♦J, ♣3, ♦2, ♦3, ♦6, ♥4, ♣6, ♠8, ♣9, ♥2, ♦9, ♦4, ♥7, ♠10, ♣8, ♦Q, ♠9, ♣Q, ♠2, ♥6, ♠7, ♠5, ♣2, ♥9, ♦5, ♥8, ♠J, ♥5, ♥A, ♣A, ♠K, ♥3, ♥10, ♦K, ♠3, ♣5, ♦8, ♣J, ♦A, ♥K, ♣K, ♦7, ♠4, ♦10, ♠A, ♥Q, ♣10, ♥J, ♣7]\n",
      "东邪: [♠A, ♠6, ♠8, ♠K, ♥3, ♥5, ♥10, ♣2, ♣4, ♦8, ♦10, ♦J, ♦K]\n",
      "西毒: [♠4, ♠5, ♠7, ♠10, ♥A, ♥6, ♥K, ♣8, ♣10, ♣J, ♦A, ♦6, ♦Q]\n",
      "南帝: [♠2, ♠Q, ♥7, ♥8, ♥9, ♥Q, ♣A, ♣5, ♣6, ♦3, ♦5, ♦7, ♦9]\n",
      "北丐: [♠3, ♠9, ♠J, ♥2, ♥4, ♥J, ♣3, ♣7, ♣9, ♣Q, ♣K, ♦2, ♦4]\n"
     ]
    }
   ],
   "source": [
    "from enum import Enum\n",
    "class Suite(Enum):\n",
    "    \"\"\"花色(枚举)\"\"\"\n",
    "    SPADE, HEART, CLUB, DIAMOND = range(4)\n",
    "for suite in Suite:\n",
    "    print(f'{suite}: {suite.value}')\n",
    "class Card:\n",
    "    \"\"\"牌\"\"\"\n",
    "    def __init__(self, suite, face):\n",
    "        self.suite = suite\n",
    "        self.face = face\n",
    "\n",
    "    def __repr__(self):\n",
    "        suites = '♠♥♣♦'\n",
    "        faces = ['', 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']\n",
    "        # 根据牌的花色和点数取到对应的字符\n",
    "        return f'{suites[self.suite.value]}{faces[self.face]}'\n",
    "    \n",
    "    def __lt__(self, other):\n",
    "        # 花色相同比较点数的大小\n",
    "        if self.suite == other.suite:\n",
    "            return self.face < other.face\n",
    "        # 花色不同比较花色对应的值\n",
    "        return self.suite.value < other.suite.value  \n",
    "import random\n",
    "\n",
    "\n",
    "class Poker:\n",
    "    \"\"\"扑克\"\"\"\n",
    "\n",
    "    def __init__(self):\n",
    "        # 通过列表的生成式语法创建一个装52张牌的列表\n",
    "        self.cards = [Card(suite, face) for suite in Suite\n",
    "                      for face in range(1, 14)]\n",
    "        # current属性表示发牌的位置\n",
    "        self.current = 0\n",
    "\n",
    "    def shuffle(self):\n",
    "        \"\"\"洗牌\"\"\"\n",
    "        self.current = 0\n",
    "        # 通过random模块的shuffle函数实现列表的随机乱序\n",
    "        random.shuffle(self.cards)\n",
    "\n",
    "    def deal(self):\n",
    "        \"\"\"发牌\"\"\"\n",
    "        card = self.cards[self.current]\n",
    "        self.current += 1\n",
    "        return card\n",
    "\n",
    "    @property\n",
    "    def has_next(self):\n",
    "        \"\"\"还有没有牌可以发\"\"\"\n",
    "        return self.current < len(self.cards)\n",
    "poker = Poker()\n",
    "poker.shuffle()\n",
    "print(poker.cards)\n",
    "class Player:\n",
    "    \"\"\"玩家\"\"\"\n",
    "\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "        self.cards = []\n",
    "\n",
    "    def get_one(self, card):\n",
    "        \"\"\"摸牌\"\"\"\n",
    "        self.cards.append(card)\n",
    "\n",
    "    def arrange(self):\n",
    "        self.cards.sort()\n",
    "        poker = Poker()\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02b298b9-e739-4b85-bda3-4fcd31947e1f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
